/*
 *  SyncIT , easy synchronization of files between computers and devices.
 *  Copyright (C) 2011  Christian Masus <cmasus(at)gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version. If redistributing and/or modifying
 *  this file, this notice must be included in the redistributed or
 *  modified copy.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package config.items;

/**
 * Defines the configuration items related to the sync clients,
 * stored as a list under "client/N/".
 * @author Christian Masus
 *
 */
public class SyncItems {

	// Default values
	private final boolean DEFAULT_ENABLED              = false;
	private final String  DEFAULT_LOCAL_PATH           = "";
	private final String  DEFAULT_REMOTE_ADDRESS       = "";
	private final int     DEFAULT_REMOTE_PORT          = 45678;
	private final String  DEFAULT_REMOTE_PATH          = "";
	private final boolean DEFAULT_ALLOW_DELETE         = false;
	private final boolean DEFAULT_USE_DELETE_DIALOG    = true;
	private final boolean DEFAULT_INCLUDE_HIDDEN_FILES = false;

	// Configuration
	private boolean enabled;
	private String  localPath;
	private String  remoteAddress;
	private int     remotePort;
	private String  remotePath;
	private boolean allowDelete;
	private boolean useDeleteDialog;
	private boolean includeHiddenFiles;


	public SyncItems() {
		loadDefaultValues();
	}


	public boolean getEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	public void setEnabled(String enabled) {
		this.enabled = new Boolean(enabled);
	}

	public String getLocalPath() {
		return localPath;
	}
	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}

	public String getRemoteAddress() {
		return remoteAddress;
	}
	public void setRemoteAddress(String remoteAddress) {
		this.remoteAddress = remoteAddress;
	}

	public int getRemotePort() {
		return remotePort;
	}
	public void setRemotePort(int remotePort) {
		if(isInternetPort(remotePort)) {
			this.remotePort = remotePort;
		}
		else {
			this.remotePort = DEFAULT_REMOTE_PORT;
		}
	}
	public void setRemotePort(String remotePort) {
		setRemotePort(new Integer(remotePort));
	}

	public String getRemotePath() {
		return remotePath;
	}
	public void setRemotePath(String remotePath) {
		this.remotePath = remotePath;
	}

	public boolean getAllowDelete() {
		return allowDelete;
	}
	public void setAllowDelete(boolean allowDelete) {
		this.allowDelete = allowDelete;
	}
	public void setAllowDelete(String allowDelete) {
		this.allowDelete = new Boolean(allowDelete);
	}

	public boolean getUseDeleteDialog() {
		return useDeleteDialog;
	}
	public void setUseDeleteDialog(boolean useDeleteDialog) {
		this.useDeleteDialog = useDeleteDialog;
	}
	public void setUseDeleteDialog(String useDeleteDialog) {
		this.useDeleteDialog = new Boolean(useDeleteDialog);
	}

	public boolean getIncludeHiddenFiles() {
		return includeHiddenFiles;
	}
	public void setIncludeHiddenFiles(boolean includeHiddenFiles) {
		this.includeHiddenFiles = includeHiddenFiles;
	}
	public void setIncludeHiddenFiles(String includeHiddenFiles) {
		this.includeHiddenFiles = new Boolean(includeHiddenFiles);
	}



	private boolean isInternetPort(int port) {
		if(port >= 0 && port <= 65535) {
			return true;
		}
		return false;
	}



	public void loadDefaultValues() {
		enabled            = DEFAULT_ENABLED;
		localPath          = DEFAULT_LOCAL_PATH;
		remoteAddress      = DEFAULT_REMOTE_ADDRESS;
		remotePort         = DEFAULT_REMOTE_PORT;
		remotePath         = DEFAULT_REMOTE_PATH;
		allowDelete        = DEFAULT_ALLOW_DELETE;
		useDeleteDialog    = DEFAULT_USE_DELETE_DIALOG;
		includeHiddenFiles = DEFAULT_INCLUDE_HIDDEN_FILES;
	}

	public String[][] getTagValuePair() {
		String[][] ret = {
				{"Enabled",            new Boolean(enabled).toString()},
				{"LocalPath",          localPath},
				{"RemoteAddress",      remoteAddress},
				{"RemotePort",         new Integer(remotePort).toString()},
				{"RemotePath",         remotePath},
				{"AllowDelete",        new Boolean(allowDelete).toString()},
				{"UseDeleteDialog",    new Boolean(useDeleteDialog).toString()},
				{"IncludeHiddenFiles", new Boolean(includeHiddenFiles).toString()}
		};
		return ret;
	}

	public String toString() {
		String ret = "";
		String[][] tagValuePair = getTagValuePair();
		for(int row = 0; row < tagValuePair.length; row++) {
			ret += tagValuePair[row][0] + " = " + tagValuePair[row][1] + "\n";
		}
		return ret;
	}
}
